          <?php
            if($session->read("Auth.User.id") && $listingData['Listing']['owner_id'] == $session->read("Auth.User.id"))
            {?>
        <?php $section->appendSystemModule('right_sidebar', array('name'=>'cms.html','params' => array('html_content' => $this->element("owner_nav"))));
?>
<?php 

     }
        ?>
<?php $section->appendSystemModule('right_sidebar', array('name'=>'cms.html','params' => array('html_content' => $this->element("listing_view_map",array('showStreetView'=>true)))));
?>
<?php
	$this->set("hideLayoutTitle",true);
	$itemScope = "";
	if(cr("ListingConfig.enable_rich_snippets"))
	{
        $entity = "Thing";
        $schemaUrl = "http://schema.org/";
        if(cr("ListingConfig.snippet_entity"))
        {
          $entity = cr("ListingConfig.snippet_entity");
        }
        $schemaUrl = "http://schema.org/".$entity;
		$itemScope = 'itemscope itemtype="'.$schemaUrl.'"';
	}
	$openGraph = array("og:title"=>$listingData['Listing']['title'],'og:site_name '=>cr("cmsConfig.Backend.siteName"),
				"og:url"=>cr("cmsConfig.Backend.siteUrl").$listingData['Listing']['viewUrl'],
				"og:description" => $listingData['Listing']['description'],
				"og:image" => cr('cmsConfig.Backend.siteUrl').$listingData['Listing']['image'],
				"fb:app_id" => cr("FacebookConfig.appId")
			);
	$openGraphContent = "";
	foreach($openGraph as $metaProperty => $metaContent)
	{
		$metaContent = htmlentities($metaContent);
		$openGraphContent .= "<meta property='$metaProperty' content='$metaContent' />";
	}
	$this->addScript($openGraphContent);

?>

<?php 
			$userReviewCount = '<div style="float:left;margin-left:80px">('.'<span>'.$listingData['Listing']['review_count'].'</span>  '.__('reviews').')</div>';
			$userRating = $listingData['Listing']['userAvg'];
			$editorRating = $listingData['Listing']['editorialAvg'];
			$userRatingHtml = $rating->display(array('rating'=>$userRating,'before_text'=>$userReviewCount,'tooltip'=>__('User Rating').' '.number_format($userRating,1)));
			$editorRatingHtml = $rating->display(array('rating'=>$editorRating,'class'=>'editor_rating_star_value','tooltip'=>__('Editor Rating').' '.number_format($editorRating,1)));

			$img = $html->image($listingData['Listing']['image'],array('thumb'=>array('crop'=>true,'width'=>630,'height'=>192),'class'=>'main_pic','alt'=>sprintf(__("%s picture"),$listingData['Listing']['title'])));
		?>	


<?php
$noImg = false; 
if($listingData['Listing']['image'] !== "/uploads/listing_image.gif") {
?>
	<div class="images_section">
	<?php
	//showing main listing image
	echo $html->link($img, array("controller"=>"listing_assets",'action'=>'index','listing','listingId'=>$listingData['Listing']['id']),array('escape'=>false));
	?>
	</div>
<?php } else { 
	$noImg = true; 
?>
	<div class="no_img"></div>
<?php } ?>
	<div class="listing_content" <?php echo $itemScope; ?>>



	                            <div class="row">
    <div class="col-xs-12 col-md-6">
    <h2>
		<?php echo $this->pageTitle?>

</h2>
<meta itemprop="name" content="<?php echo h($listingData['Listing']['title'])?>" />
	<meta itemprop="url" content="<?php echo Router::url($listingData['Listing']['viewUrl'],true);?>" />
	<meta itemprop="image" content="<?php echo Router::url($listingData['Listing']['image'],true)?>" />
	
	
		<!--Added <?php echo __("by ")?>  
		<?php echo $html->link($listingData['Listing']['poster']['display_name'],$listingData['Listing']['poster']['profile_url'],array('class'=>'poster'))?> -->
		
		<!--<?php echo __("Posted On")?></b><span itemprop="dateCreated"> <?php echo date('Y-m-d',strtotime($listingData['Listing']['created']));?></span>-->
		
		<!-- listing avg rating code starts here -->
	
		
	
		<div class="ratings">
			<?php echo $userRatingHtml;?>
            
			<?php //show editorial rating if "disableEditorReviews" config is enabled.
			if(cr('GeneralConfig.disable_editor_reviews') != 1)
			{
				echo $editorRatingHtml;
			}?>
            <?php 
                  $totalReviewCount = $listingData['Listing']['review_count'];
                  $totalRating = ($listingData['Listing']['userAvg']);
                  if($listingData['Listing']['editorialAvg'])
                  {
                    $totalReviewCount++;
                    $totalRating = ($totalRating + $listingData['Listing']['editorialAvg'])/2;
                  }
                  if($totalReviewCount && cr("ListingConfig.enable_rich_snippets") && $entity != "Thing"){
                ?>
                  <span itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
                    <meta itemprop="reviewCount" content="<?php echo $totalReviewCount?>"/>
                    <meta itemprop="ratingValue" content="<?php echo $totalRating?>"/>
                    <meta itemprop="bestRating" content="<?php echo Review::RATING_MAX_VALUE?>>"/>
                  </span>
                 <?php } ?> 
		</div>
					<?php echo $listingInformation->showListingCategories($listingData);?> <br/>
					<div class="address">
						<?php 
						$FieldPropertyObject = $listingInformation->getAttributes($listingData);
						$contactInfoFields = $FieldPropertyObject->getFieldsetInfo(1);
						$contactInfoFields = $contactInfoFields['fields'];
						?>
							<?php echo $listingInformation->getDirectValue($listingData,"address");?><br/>

							<?php echo $listingInformation->getDirectValue($listingData,"city");?>

							<?php echo $listingInformation->getDirectValue($listingData,"state");?>
							<?php echo $listingInformation->getDirectValue($listingData,"zipcode");?><br/>
							<?php echo $listingInformation->getDirectValue($listingData,"phone");?><br/>
							<?php echo $listingInformation->getDirectValue($listingData,"website");?>
							<?php foreach($contactInfoFields as $contactField) { 
								if(!in_array($contactField, array("address", "city", "state", "zipcode", "phone", "website"))) {
									echo $listingInformation->showField($listingData, $contactField);
							} } ?>





</div>
		<?php 
		if(cr("FacebookConfig.appId") && cr("ListingConfig.enable_fb_like"))
		{
			$fbLikeUrl = $html->url($listingData['Listing']['viewUrl'], true);
			//$fbLikeUrl = rawurlencode($fbLikeUrl);
			?>
			<div class="clear"></div>
			<div>
			<br/>

				<iframe frameborder=0  width="200" height="22" src="http://www.facebook.com/plugins/like.php?href=<?php echo $fbLikeUrl ?>&width=100&layout=button_count&action=like&show_faces=true&share=false&height=21&appId=<?php echo cr("FacebookConfig.appId") ?>"></iframe>
			</div>
			<?php 
		}
		?>


</div>
    <div class="col-xs-12 col-md-6">
    	 <?php
    	 $allowImageLinks = true;
    	 if(!empty($listingAssets))
		{
		?>
	<ul class="media-list">
		<?php
			$imageLimit = 3;
			$i = 0;
			foreach($listingAssets as $listingAsset)
			{
				$listingAsset = $listingAsset['ListingAsset'];
				?>
				<?php 
				if($i == $imageLimit)
				{
					break;
				}				
				?>
      <li class="col-xs-4 col-md-4 images_section">
        <?php echo $html->link($html->image($listingAsset['file_url'],array('class'=>'thumbnail','thumb'=>array('crop'=>true,'width'=>60,'height'=>45))),array("controller"=>"listing_assets",'action'=>'index','listing','listingId'=>$listingData['Listing']['id'],'show'=>$listingAsset['id']),array('escape'=>false));?>
        
      </li>
      <?php $i++;
			}?>
    </ul>
    	<?php
				
				if(AppUtility::allowPaidListing())
				{
					$EffectivePlan = cri("PaidListings.ListingPlan")->getEffectivePlan($listingData['Listing']['id']);
					if($EffectivePlan->limitImages())
					{
						$allowImageLinks = false;
						$allowedImagesCount = $EffectivePlan->getAllowedTotalImagesCount();
         
						if($allowedImagesCount > 0 && count($listingAssets) < ($allowedImagesCount - 1))
						{
                          
							if($listingData['Listing']['owner_id'] == $session->read("Auth.User.id") || $EffectivePlan->allowGallery())
							{
								$allowImageLinks = true;
							}
						}
					}
				}
			?>
    	<?php }?>
<?php if($allowImageLinks){?>
				<?php 
				$uploadPicCl = "";
				if($noImg) $uploadPicCl = " noImage";
				echo $html->link(__('Upload pic'),array('controller'=>'listing_assets','action'=>'add',$listingData['Listing']['id']),array('class'=>'fr'.$uploadPicCl));?>
			<?php } ?>
             <?php if(!$noImg && (count($listingAssets) || !AppUtility::allowPaidListing())){?>   
                  <div class="fr">|</div><?php echo $html->link(__('View All Pics'),array("controller"=>"listing_assets",'action'=>'index','listing','listingId'=>$listingData['Listing']['id']),array('class'=>'fr togallerylink'))?>
              <?php } ?>
    </div>
    </div>

   


	
		
		<div class="clear"></div>
		<div>
		<?php 
			if($listingData["Listing"]['lat'] && $listingData["Listing"]['lng'])
			{
				echo $html->link(__("Get directions"),array("plugin"=>null,"controller"=>"listings","action"=>"getDirections",$listingData["Listing"]["slug"]),array("escape"=>false,"class"=>""));
			}
		?>
		</div>
		
		<!-- listing avg rating code ends here -->	
		<div class="clear"></div>
			<?php
			//render element to show custom field info 
			echo $this->element('listing_view_fields',array('ListingModelObj'=>$ListingModelObj,'listingDefaultFields'=>$listingDefaultFields));
		?>




	<div class ='description' itemprop="description">
		<?php
		if(!empty($listingData['Listing']['description']))
		{?>
	<hr>
			<b><?php echo __('Description')?>:</b>
			<?php 
				if(cr('ListingConfig.flay_text'))
				{
					echo $appHtml->flayText($listingData['Listing']['description'],cr('ListingConfig.flay_text'));
				}else
				{
					echo $listingData['Listing']['description'];
				}
				
		}
		?>
	</div>
		
		<?php  if(cr("GeneralConfig.enable_tags")){?>
		<b><?php echo __('Tags')?>:</b>
		<?php
		if($listingData['Listing']['tags'])
		{
			$tagsToShow = '';
			foreach($listingData['Listing']['tags'] as $tag)
			{
				$tagsToShow .=  $html->link($tag['tag'],'/listings/index/tags/'.$tag['slug']).',';
			}
			echo '<span itemprop="keywords">'.substr($tagsToShow,0,-1).'</span>';
		}else
		{
			echo __('N/A');
		}
		?>
		<?php }?>
<div class="clear"></div>
	<br>
	<div class="pull-right">
			<?php echo $appHtml->shareLinks();?>
		</div>
		<div class="clearfix"></div>
<hr>



		<?php if(cr("ListingConfig.business_owner") && $session->read("Auth.User.id") && !$listingData['Listing']['owner_id']){?>
			<div class="ask_owner">
				<?php echo String::insert(__("Are you owner of this listing? :claim_link"),array('claim_link'=>$html->link(__("Claim it now"),array("controller"=>"listing_claims","action"=>"claim",$listingData['Listing']['id']))))?>
			</div>
			<div class="clear"></div>

		<?php } ?> 
	<!-- listing action info starts here -->
	<div class="review_bottom">
		
		<?php if($session->read('Auth.User'))
		{?>

			<div class="favriotes">
				<i class="fa fa-heart"> </i> <?php echo $userContent->toggleFavorites($listingData['Listing']['id'],'Listing');?> 
			</div>
		<?php }?>
		<div class="button">
		<i class="fa fa-envelope"> </i> <?php echo $html->link(__('Send to friends'),'/inviteFriends/'.$listingData['Listing']['id'],array('class'=>''))?> 
	</div>
		<?php 
		$isOwner = cr("ListingConfig.business_owner") && $session->read("Auth.User.id") && $listingData['Listing']['owner_id'] == $session->read("Auth.User.id");
		if($hasReviewd == false && $isOwner == false)
		{
			echo " <div class='button'><i class='fa fa-star'> </i> ".$html->link(__('Write a Review'),'/reviews/add/'.$listingData['Listing']['id'],array());
			echo " </div> ";
		}
		
		?>
		
	</div>
	<!-- listing action info ends here -->

<br /><br />



<!-- Deals Section Starts Here -->
<?php
if(cr("DealConfig.enable_deals"))
{
	if(isset($deals) && !empty($deals))
	{
		echo $this->element('listing_deals_element',array('deals'=>$deals,'plugin'=>'deals','showDeleteButton'=>(($isOwner == true)?true:false)));
	}
}
?>
<!-- Deals Section Ends Here  -->
<br />

<div class="reviews_section" id="listing_reviews_<?php echo $listingData['Listing']['id']?>">
<?php
//showing editorial review.
if(cr('GeneralConfig.disable_editor_reviews')!= 1)
{?>	
	<?php 
	if(!empty($editorialReview))
	{?>
		<h3><?php echo __('Editor Review')?></h3>
		<?php echo $this->element('reviews', array('showAvatar'=>true,'reviews' => array($editorialReview),'view_type'=>'blog_view', 'full_description' => true));?>
	<?php }?>
<?php 
}?>


	<h3><?php echo __("User Reviews");?> (<?php echo $listingData['Listing']['review_count']?>)</h3>
	<?php echo $ajax->div('/reviews/index/listing/listingId:'.$listingData['Listing']['id'].'/full_description:true', array('preload' => true, 'recursive' => false));?>
</div>
</div>

<?php if(cr("GeneralConfig.lightboxGallery")){//changeCheck 1==1
 $javascript->link("/js/jquery.lightbox.min",false); 
 $html->css("/css/jquery.lightbox.css",null,array(),false);
 ?>
<script type="text/javascript">
$(document).ready(function(){
  var elems = [];
  var windowHeight = $(window).height();
  var windowWidth = $(window).width();
  var imgHeight = 0.8*windowHeight;
  var imgWidth = 0.8*windowWidth;
  imgHeight = imgHeight > 800 ? 800 : imgHeight;
  imgWidth = imgWidth > 800 ? 800 : imgWidth;
  $('.images_section img').each(function(){
    var obj = $(this);
    var url = obj.attr("src");
    url = url.replace('/crop/', '/');
    url = url.replace(/\d+x\d+/,imgWidth+'x'+imgHeight);
    var anchor = obj.parent('a');
    anchor.attr("href",url);
    elems.push(anchor[0]);
  });
  if(elems.length)
   {
     $(elems).lightBox({fixedNavigation:false});
      $('.togallerylink').click(function(e){
        //e.preventDefault();
        //$(elems[0]).trigger('click');
    });
  }
  
});
</script>
<?php } ?>